#import <stdio.h>
#import "drawingEvent.h"

@implementation DrawingEvent

-(id) initWithCommunicator:(id<ICECommunicator>)c andType:(DrawingEventType)d_evt_type
{
	[super initWithCommunicator:c];
	
	[self setMember:@"type" value:[self fromInt:DRAWING_EVENT_TYPE]];
	[self setMember:@"drawing_event_type" value:[self fromInt:d_evt_type]];
	[self setMember:@"color" value:[self fromString:@"0x000000"]];
	
	return self;
}

-(int) subType
{
	return [self interpretInt:[self memberValue:@"drawing_event_type"]];
}

-(NSString*) color
{
	return [self interpretString:[self memberValue:@"color"]];
}

-(void) setColor:(NSString*)color
{
	[self setMember:@"color" value:[self fromString:color]];
}

@end


@implementation LineEvent

-(id) initWithCommunicator:(id<ICECommunicator>)c x0:(float)_x0 y0:(float)_y0 x1:(float)_x1 y1:(float)_y1
{
	[super initWithCommunicator:c andType:LINE];
	
	[self setMember:@"x0" value:[self fromFloat:_x0]];
	[self setMember:@"y0" value:[self fromFloat:_y0]];
	[self setMember:@"x1" value:[self fromFloat:_x1]];
	[self setMember:@"y1" value:[self fromFloat:_y1]];
	
	return self;
}

-(float) x0
{
	return [self interpretFloat:[self memberValue:@"x0"]];
}

-(float) y0
{
	return [self interpretFloat:[self memberValue:@"y0"]];
}

-(float) x1
{
	return [self interpretFloat:[self memberValue:@"x1"]];
}

-(float) y1
{
	return [self interpretFloat:[self memberValue:@"y1"]];
}

@end


@implementation RectangleEvent

-(id) initWithCommunicator:(id<ICECommunicator>)c x:(float)_x y:(float)_y width:(float)w height:(float)h
{
	[super initWithCommunicator:c andType:RECTANGLE];
	
	[self setMember:@"x" value:[self fromFloat:_x]];
	[self setMember:@"y" value:[self fromFloat:_y]];
	[self setMember:@"width" value:[self fromFloat:w]];
	[self setMember:@"height" value:[self fromFloat:h]];
	
	return self;
}

-(float) x
{
	return [self interpretFloat:[self memberValue:@"x"]];
}

-(float) y
{
	return [self interpretFloat:[self memberValue:@"y"]];
}

-(float) width
{
	return [self interpretFloat:[self memberValue:@"width"]];
}

-(float) height
{
	return [self interpretFloat:[self memberValue:@"height"]];
}

@end


@implementation FilledRectangleEvent

-(id) initWithCommunicator:(id<ICECommunicator>)c x:(float)_x y:(float)_y width:(float)w height:(float)h
{
	[super initWithCommunicator:c x:_x y:_y width:w height:h];
	
	[self setMember:@"fill_color" value:[self fromString:@"0xffffff"]];
	[self setMember:@"drawing_event_type" value:[self fromInt:FILLED_RECTANGLE]];
	
	return self;
}

-(NSString*) fillColor
{
	return [self interpretString:[self memberValue:@"fill_color"]];
}

-(void) setFillColor:(NSString*)color
{
	[self setMember:@"fill_color" value:[self fromString:color]];
}

@end


@implementation EllipseEvent

-(id) initWithCommunicator:(id<ICECommunicator>)c x:(float)_x y:(float)_y width:(float)w height:(float)h
{
	[super initWithCommunicator:c andType:ELLIPSE];
	
	[self setMember:@"x" value:[self fromFloat:_x]];
	[self setMember:@"y" value:[self fromFloat:_y]];
	[self setMember:@"width" value:[self fromFloat:w]];
	[self setMember:@"height" value:[self fromFloat:h]];
	
	return self;
}

-(float) x
{
	return [self interpretFloat:[self memberValue:@"x"]];
}

-(float) y
{
	return [self interpretFloat:[self memberValue:@"y"]];
}

-(float) width
{
	return [self interpretFloat:[self memberValue:@"width"]];
}

-(float) height
{
	return [self interpretFloat:[self memberValue:@"height"]];
}

@end


@implementation FilledEllipseEvent

-(id) initWithCommunicator:(id<ICECommunicator>)c x:(float)_x y:(float)_y width:(float)w height:(float)h
{
	[super initWithCommunicator:c x:_x y:_y width:w height:h];
	
	[self setMember:@"fill_color" value:[self fromString:@"0xffffff"]];
	[self setMember:@"drawing_event_type" value:[self fromInt:FILLED_ELLIPSE]];
	
	return self;
}

-(NSString*) fillColor
{
	return [self interpretString:[self memberValue:@"fill_color"]];
}

-(void) setFillColor:(NSString*)color
{
	[self setMember:@"fill_color" value:[self fromString:color]];
}

@end


@implementation CircleEvent

-(id) initWithCommunicator:(id<ICECommunicator>)c x:(float)_x y:(float)_y radius:(float)r
{
	[super initWithCommunicator:c andType:CIRCLE];
	
	[self setMember:@"x" value:[self fromFloat:_x]];
	[self setMember:@"y" value:[self fromFloat:_y]];
	[self setMember:@"radius" value:[self fromFloat:r]];
	
	return self;
}

-(float) x
{
	return [self interpretFloat:[self memberValue:@"x"]];
}

-(float) y
{
	return [self interpretFloat:[self memberValue:@"y"]];
}

-(float) radius
{
	return [self interpretFloat:[self memberValue:@"radius"]];
}

@end


@implementation FilledCircleEvent

-(id) initWithCommunicator:(id<ICECommunicator>)c x:(float)_x y:(float)_y radius:(float)r
{
	[super initWithCommunicator:c x:_x y:_y radius:r];
	
	[self setMember:@"fill_color" value:[self fromString:@"0xffffff"]];
	[self setMember:@"drawing_event_type" value:[self fromInt:FILLED_CIRCLE]];
	
	return self;
}

-(NSString*) fillColor
{
	return [self interpretString:[self memberValue:@"fill_color"]];
}

-(void) setFillColor:(NSString*)color
{
	[self setMember:@"fill_color" value:[self fromString:color]];
}

@end


@implementation TriangleEvent

-(id) initWithCommunicator:(id<ICECommunicator>)c x0:(float)_x0 y0:(float)_y0 x1:(float)_x1 y1:(float)_y1 x2:(float)_x2 y2:(float)_y2
{
	[super initWithCommunicator:c andType:TRIANGLE];
	
	[self setMember:@"x0" value:[self fromFloat:_x0]];
	[self setMember:@"y0" value:[self fromFloat:_y0]];
	[self setMember:@"x1" value:[self fromFloat:_x1]];
	[self setMember:@"y1" value:[self fromFloat:_y1]];
	[self setMember:@"x2" value:[self fromFloat:_x2]];
	[self setMember:@"y2" value:[self fromFloat:_y2]];
	
	return self;
}

-(float) x0
{
	return [self interpretFloat:[self memberValue:@"x0"]];
}

-(float) y0
{
	return [self interpretFloat:[self memberValue:@"y0"]];
}

-(float) x1
{
	return [self interpretFloat:[self memberValue:@"x1"]];
}

-(float) y1
{
	return [self interpretFloat:[self memberValue:@"y1"]];
}

-(float) x2
{
	return [self interpretFloat:[self memberValue:@"x2"]];
}

-(float) y2
{
	return [self interpretFloat:[self memberValue:@"y2"]];
}

@end


@implementation FilledTriangleEvent

-(id) initWithCommunicator:(id<ICECommunicator>)c x0:(float)_x0 y0:(float)_y0 x1:(float)_x1 y1:(float)_y1 x2:(float)_x2 y2:(float)_y2
{
	[super initWithCommunicator:c x0:_x0 y0:_y0 x1:_x1 y1:_y1 x2:_x2 y2:_y2];
	
	[self setMember:@"fill_color" value:[self fromString:@"0xffffff"]];
	[self setMember:@"drawing_event_type" value:[self fromInt:FILLED_TRIANGLE]];
	
	return self;
}

-(NSString*) fillColor
{
	return [self interpretString:[self memberValue:@"fill_color"]];
}

-(void) setFillColor:(NSString*)color
{
	[self setMember:@"fill_color" value:[self fromString:color]];
}

@end


@implementation HandDrawEvent

-(id) initWithCommunicator:(id<ICECommunicator>)c npoints:(int)n
{
	[super initWithCommunicator:c andType:HAND_DRAW];
	
	int i;
	for (i=0; i<n; i++)
	{
		[self setMember:[NSString stringWithFormat:@"x%d", i] value:[self fromFloat:0]];
		[self setMember:[NSString stringWithFormat:@"y%d", i] value:[self fromFloat:0]];
	}
	
	[self setMember:@"npoints" value:[self fromInt:n]];
	
	return self;
}

-(int) npoints
{
	return [self interpretInt:[self memberValue:@"npoints"]];
}

-(float) xn:(int)n
{
	return [self interpretFloat:[self memberValue:[NSString stringWithFormat:@"x%d", n]]];
}

-(float) yn:(int)n
{
	return [self interpretFloat:[self memberValue:[NSString stringWithFormat:@"y%d", n]]];
}

-(void) setXn:(int)n x:(float)_x
{
	[self setMember:[NSString stringWithFormat:@"x%d", n] value:[self fromFloat:_x]];
}

-(void) setYn:(int)n y:(float)_y
{
	[self setMember:[NSString stringWithFormat:@"y%d", n] value:[self fromFloat:_y]];
}

@end
